package part2;

public class ParaDrop{

	public static void execute(Board b, int x, int y, int color) {
		if(isValid(b, x, y, color)) {
			b.boardColors[x][y] = color;
			//System.out.println("Move " + color + "/(" + x + "," + y + ") Sucess");
		}
		//System.out.println("Move " + color + "/(" + x + "," + y + ") Fail");
	}

	public static boolean isValid(Board b, int x, int y, int color) {
		if(b.boardColors[x][y] != 0 ) {
			return false;
		}
		if(x>0 && b.boardColors[x-1][y] == color) {
			return false;
		}
		if(y>0 && b.boardColors[x][y-1] == color) {
			return false;
		}
		if(x<b.boardColors.length-1 && b.boardColors[x+1][y] == color) {
			return false;
		}
		if(y<b.boardColors[0].length-1 && b.boardColors[x][y+1] == color) {
			return false;
		}
		return true;
	}


}
